home *** CD-ROM | disk | FTP | other *** search
- #include <exec/memory.h>
- #include <graphics/gfx.h>
- #include <graphics/gfxbase.h>
- #include <graphics/gfxmacros.h>
- #include <graphics/displayinfo.h>
- #include <graphics/sprite.h>
- #include <hardware/custom.h>
- #include <hardware/dmabits.h>
- #include <intuition/intuition.h>
- #include <intuition/intuitionbase.h>
- #include <cybergraphics/cybergraphics.h>
-
- #include <proto/exec.h>
- #include <proto/graphics.h>
- #include <proto/intuition.h>
- #include <proto/cybergraphics.h>
-
- #include "code.h"
- #include "yak.h"
- #include "blankers.h"
- #include "handlers.h"
- #include "settings.h"
-
- struct Library *CyberGfxBase;
-
- extern __far struct Custom custom;
-
- #define TURN_OFF_SPRITES {OFF_SPRITE;custom.spr[0].dataa = custom.spr[0].datab = 0;}
-
- static BOOL mouseoff = FALSE; /* is mouse off? (MB_SPRITES only) */
- static BOOL blanked = FALSE;
- static struct Screen *blankscr;
-
-
- static void PowerSaveBlank(void);
- static void PowerSaveUnBlank(void);
-
- static void
- PowerSaveBlank(void)
- {
- if (CyberGfxBase = OpenLibrary("cybergraphics.library", 40L))
- {
- CVideoCtrlTags(&blankscr->ViewPort, SETVC_DPMSLevel, DPMS_OFF, TAG_DONE);
- }
- }
-
- static void
- PowerSaveUnBlank(void)
- {
- if (CyberGfxBase != NULL)
- {
- CVideoCtrlTags(&blankscr->ViewPort, SETVC_DPMSLevel, DPMS_ON, TAG_DONE);
-
- CloseLibrary(CyberGfxBase);
- }
- }
-
-
- static BOOL
- OpenBlankingScreen (void)
- {
- ULONG modeid = INVALID_ID;
-
- Forbid ();
- if (IntuitionBase->FirstScreen)
- modeid = GetVPModeID (&(IntuitionBase->FirstScreen->ViewPort));
- Permit ();
- if (modeid == INVALID_ID)
- modeid = LORES_KEY;
-
- if (blankscr = OpenScreenTags (NULL, SA_Depth, 1,
- SA_Title, "Yak blanking screen",
- SA_Quiet, TRUE,
- SA_Behind, TRUE,
- SA_DisplayID, modeid,
- TAG_DONE))
- {
- SetRGB4 (&blankscr->ViewPort, 0, 0, 0, 0);
- ScreenToFront (blankscr);
-
- return(TRUE);
- }
- return(FALSE);
- }
-
-
- static struct Window *BlankWnd;
-
- __chip static UWORD Pointer[6] = {0,0,0,0,0,0};
- static BOOL OwnBlankWnd = FALSE;
-
- static void
- UnblankMousePointer( void )
- {
- if ( BlankWnd != NULL )
- {
- ClearPointer( BlankWnd );
-
- if (OwnBlankWnd == TRUE)
- {
- OwnBlankWnd = FALSE;
- CloseWindow( BlankWnd );
- }
- }
- }
-
- static void
- BlankMousePointer( void )
- {
- struct Window *Win=NULL;
- struct Screen *Scr;
- ULONG lock;
-
- lock = LockIBase(0);
- Win = IntuitionBase->ActiveWindow;
- UnlockIBase(lock);
-
- if (Win == NULL)
- {
- Scr = ScreenUnderMouse();
-
- Win = OpenWindowTags (0L,
- WA_Activate, TRUE,
- WA_Left, 0,
- WA_Top, 0,
- WA_Width, 1,
- WA_Height, 1,
- WA_Borderless, TRUE,
- WA_CustomScreen, Scr,
- TAG_END );
- if (Win != NULL)
- {
- OwnBlankWnd = TRUE;
- }
- else
- {
- OwnBlankWnd = FALSE;
- return;
- }
- }
-
- if (Win != BlankWnd)
- {
- UnblankMousePointer();
- BlankWnd = Win;
- }
-
- SetPointer( BlankWnd, Pointer, 1, 16, 0, 0 );
- }
-
-
-
- void
- ForceTurnMouseOff ()
- {
- /* Force reblank */
- mouseoff = FALSE;
- TurnMouseOff();
- }
-
- void
- TurnMouseOff () /* blank mouse-pointer */
- {
- if (mouseoff == FALSE) /* no point in turning it off twice... */
- {
- Forbid ();
-
- if (mouseblank == MB_SPRITES)
- {
- WaitTOF ();
- OFF_SPRITE;
- custom.spr[0].dataa = custom.spr[0].datab = 0;
- }
- else
- {
- BlankMousePointer();
- }
-
- Permit ();
-
- mouseoff = TRUE;
- }
- }
-
-
- void
- TurnMouseOn () /* restore mouse-pointer */
- {
- if (mouseoff == TRUE)
- {
- if (mouseblank == MB_SPRITES) /* really dirty blanking */
- { /* but guaranteed to work... */
- Forbid ();
- WaitTOF ();
- ON_SPRITE;
- Permit ();
- }
- else
- {
- UnblankMousePointer();
- }
- mouseoff = FALSE;
- }
- }
-
-
-
- void
- BlankScreen ()
- {
- switch (screenblank)
- {
- case SB_DMA:
- if (blackborder == FALSE)
- {
- /* If border is not blanked, DMA blanking will use
- * screen background color which something else than black
- * To avoid this, we open a black screen
- */
- blanked = OpenBlankingScreen();
- }
-
- /* Turn DMA off */
- custom.dmacon = BITCLR|DMAF_RASTER|DMAF_COPPER|DMAF_SPRITE;
-
- if (blankscr != NULL)
- {
- /* Close screen to save some memory, if user has chosen DMA
- * blanking it, it's to save memory and CPU usage !
- */
- CloseScreen (blankscr);
- blankscr = NULL;
- }
- blanked = TRUE;
- break;
-
- case SB_BLACKSCREEN:
- if (blankscr)
- {
- ScreenToFront (blankscr);
- }
- else
- {
- blanked = OpenBlankingScreen();
- }
- break;
-
- case SB_POWERSAVE:
- if (blankscr == NULL)
- {
- blanked = OpenBlankingScreen();
- if (blanked)
- {
- PowerSaveBlank();
- }
- }
- break;
- }
-
- /* Blank mouse in case 'DMA off' didn't work (case of PICASSO II board) */
- ForceTurnMouseOff();
- }
-
-
- void
- UnBlankScreen ()
- {
- switch (screenblank)
- {
- case SB_DMA:
- /* Turn DMA on */
- custom.dmacon = BITSET|DMAF_RASTER|DMAF_COPPER|DMAF_SPRITE;
- break;
-
- case SB_BLACKSCREEN:
- if (blankscr)
- {
- CloseScreen (blankscr);
- blankscr = NULL;
- ON_SPRITE;
- }
- break;
-
- case SB_POWERSAVE:
- if (blankscr)
- {
- PowerSaveUnBlank();
- CloseScreen (blankscr);
- blankscr = NULL;
- ON_SPRITE;
- }
- break;
- }
-
- blanked = FALSE;
-
- }
-
- void
- UnBlankScreenAndMouse ()
- {
- UnBlankScreen ();
-
- /* UnBlank mouse in case 'DMA on' or 'ON_SPRITE' didn't work (case of PICASSO II board) */
- TurnMouseOn();
- }
-
-
-